package cn.jly.servlet3.config;

import cn.jly.servlet3.interceptor.MyHandlerInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @EnableWebMvc 开启spring mvc定制配置功能
 *
 * @author lanyangji
 * @description spring mvc配置类
 * @date 2020/11/14 下午 6:40
 */
@EnableWebMvc
@Configuration
@ComponentScan(basePackages = "cn.jly.servlet3", includeFilters = {
        @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Controller.class)
}, useDefaultFilters = false)
public class WebConfig implements WebMvcConfigurer {

    /**
     * 添加自定义的拦截器
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        final InterceptorRegistration interceptorRegistration =
                registry.addInterceptor(new MyHandlerInterceptor());
        interceptorRegistration.addPathPatterns("/**");
    }

    /**
     * 配置静态资源，给tomcat处理
     * 
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}
